﻿using System;
using System.Web.Helpers;
using System.Web.Mvc;
using Xoohoo.Extensions;
using Xoohoo.Models.InputModels;

namespace Xoohoo.Modules.Admin.ModelBinders
{
    public class SiteInputModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var valueProvider = bindingContext.ValueProvider;

            SiteInput site = new SiteInput
            {
                SiteName = valueProvider.GetAttemptedValue("SiteName"),
                SiteHost = valueProvider.GetAttemptedValue("SiteHost"),
                SiteTitle = valueProvider.GetAttemptedValue("SiteTitle"),
                SiteKeywords = valueProvider.GetAttemptedValue("SiteKeywords"),
                SiteDescription = valueProvider.GetAttemptedValue("SiteDescription"),
                Copyright = controllerContext.HttpContext.Request.Unvalidated("Copyright"),
                FavIconUrl = valueProvider.GetAttemptedValue("FavIconUrl"),
                PageTitleSeparator = valueProvider.GetAttemptedValue("PageTitleSeparator"),
                SkinsPath = valueProvider.GetAttemptedValue("SkinsPath"),
                AdminPath = valueProvider.GetAttemptedValue("AdminPath")
            };
            return site;
        }
    }
}
